<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="款号:" class="myform-item">
          <el-input
            v-model="form.type_no"
            placeholder="请输入款号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="SKU:" class="myform-item">
          <el-input
            v-model="form.sku_code"
            placeholder="请输入SKU"
            clearable
          ></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button type="primary" @click="onAdd">新增吊牌</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="品名" align="center" prop="product_name">
      </el-table-column>
      <el-table-column label="款号" align="center" prop="type_no">
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="sku_code">
      </el-table-column>
      <el-table-column label="安全类别" align="center" prop="safety_category">
      </el-table-column>
      <el-table-column
        label="执行标准"
        align="center"
        prop="executive_standard"
      >
      </el-table-column>
      <el-table-column label="面料" align="center" prop="fabric">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" size="default" @click="onEdit(row.id)"
            >编辑</el-button
          >
          <el-button
            type="text"
            style="color: red"
            size="default"
            @click="onDelete(row.id)"
            >删除</el-button
          >
          
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminCodeGetTag"
    />
    
  </div>
</template>

<script>
import {
  postAdminCodeGetTag,
  postAdminCodeDelTag,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dataDP: "",
      form: {
        type_no: "",
        sku_code: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;

    this.postAdminCodeGetTag(form);
  },
  methods: {
    
    // 新增
    onAdd() {
      this.$router.push({ name: "MaintenanceDetail" });
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      this.$confirm("确定删除该面料?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminCodeDelTag(obj).then((res) => {
            let form = this.form;
            this.postAdminCodeGetTag(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 编辑
    onEdit(id) {
      this.$router.push({ name: "MaintenanceDetail", query: { id } });
    },
    // 采购列表
    async postAdminCodeGetTag(data) {
      this.loading = true;
      this.form = data;
      postAdminCodeGetTag(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminCodeGetTag(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>

.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
